package net.neptech.controller;

import lombok.RequiredArgsConstructor;
import net.neptech.constants.ValidGroup;
import net.neptech.service.WorkflowService;
import net.neptech.vm.ResponseResult;
import net.neptech.model.vo.WorkflowVO;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Saya
 * @Date 2025/8/20 11:41
 * @Description TODO
 **/
@RestController
@RequestMapping("flow")
@RequiredArgsConstructor
public class WorkflowController {

    private final WorkflowService workflowService;

    /**
     * 根据流程唯一标识查询流程列表
     */
    @GetMapping("/getListByUniqueId/{uniqueId}")
    public ResponseResult<WorkflowVO> getListByUniqueId(@PathVariable String uniqueId) {
        return ResponseResult.success(workflowService.getListByUniqueId(uniqueId));
    }

    /**
     * 设置主流程
     */

    @PostMapping("setMainProcess/{flowId}")
    public ResponseResult<Void> setMainProcess(@PathVariable String flowId) {
        workflowService.setMainWorkflow(flowId);
        return ResponseResult.success();
    }

    /**
     * 获取详细数据
     */
    @GetMapping("getDetail")
    public ResponseResult<WorkflowVO> getDetail(String flowId) {
        return ResponseResult.success(workflowService.getDetail(flowId));
    }

    /**
     * 创建流程
     */

    @PostMapping("create")
    public ResponseResult<Void> create(@Validated(value = ValidGroup.Crud.Create.class) @RequestBody WorkflowVO workflowVO) {
        workflowService.create(workflowVO);
        return ResponseResult.success() ;
    }

    /**
     * 编辑表单
     *
     * @param flowId  摸板ID
     * @param type    类型 stop using delete
     * @param groupId 流程组id
     * @return 操作结果
     */

    @PutMapping("update/{flowId}")
    public ResponseResult<Void> update(@PathVariable String flowId,
                                 @RequestParam String type,
                                 @RequestParam(required = false) Long groupId) {
        workflowService.update(flowId, type, groupId.toString());
        return ResponseResult.success();
    }
}
